﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;

namespace WindowsService.WCF
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的接口名“IWCFService”。
    [ServiceContract]
    public interface IWCFService
    {
        [OperationContract,WebGet(ResponseFormat = WebMessageFormat.Json)]
        IList<Person> All();

        [OperationContract, WebInvoke(UriTemplate = "Get/{id}",
          Method = "GET",
          BodyStyle = WebMessageBodyStyle.Bare,
          ResponseFormat = WebMessageFormat.Json)]
        Person GetPerson(string id);

        [OperationContract,WebInvoke(UriTemplate = "Put/{id}",
          Method = "PUT",
          BodyStyle = WebMessageBodyStyle.WrappedRequest,
          RequestFormat = WebMessageFormat.Json,
          ResponseFormat = WebMessageFormat.Json)]
        OperationFeedback UpdatePerson(string id, string name, bool sex, int age);

        [OperationContract, WebInvoke(UriTemplate = "Post",
          Method = "POST",
          BodyStyle = WebMessageBodyStyle.Bare,
          RequestFormat = WebMessageFormat.Json,
          ResponseFormat = WebMessageFormat.Json)]
        OperationFeedback AddPerson(Person person);

        [OperationContract, WebInvoke(UriTemplate = "Delete/{id}",
          Method = "DELETE",
          BodyStyle = WebMessageBodyStyle.Bare)]
        Boolean DeletePerson(string id);

        [OperationContract, WebInvoke(UriTemplate = "IndexOf",
          Method = "POST",
          BodyStyle = WebMessageBodyStyle.Bare,
          RequestFormat = WebMessageFormat.Json,
          ResponseFormat = WebMessageFormat.Json)]
        Int32 IndexOf(Person person);
    }

    [DataContract]
    public class Person
    {
        [DataMember]
        public string id { get; set; }
        [DataMember]
        public string name { get; set; }
        [DataMember]
        public bool sex{get;set;}
        [DataMember]
        public int age { get; set; }
    }

    [DataContract]
    public class OperationFeedback
    {
        [DataMember]
        public bool result { get; set; }
        [DataMember]
        public Person data { get; set; }
    }
}
